<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Response;

class CheckJSON
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        // 检查是否为 AJAX 异步请求
        if(!$request->ajax()){
            return response()->json(['status' =>false ,'msg'=>trans('error.need_ajax')])->header('Content-Type', 'xml');
        }
        //  检查是否为 POST
        if( $request->method() != 'POST' ){
            return response()->json(['status' =>false ,'msg'=>trans('error.need_post')])->header('Content-Type', 'xml');
        }
        return $next($request);
    }
}
